package com;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.domain.Article;
import com.domain.User;
import com.service.ArticleService;
import com.service.UserService;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class MyBatisTestBySpring {
	
	@Resource
	private UserService userService;
	
	@Resource
	private ArticleService articleService;
	
/*	@Test
    public void testAddUser(){
        User user = new User();
        user.setUserName("xdp");
        user.setName("batchUpdateByPrimaryKey1");
        user.setCreater(0);
        for (int i = 0; i < 1000000; i++) {
        	userService.addUser(user);
		}
    }*/
	
	/*@Test
	public void testAddUsers(){
		User user = new User();
		user.setUserName("xdp");
		user.setName("batchUpdateByPrimaryKey1");
		user.setCreater(0);
		ArrayList<User> arrayList = new ArrayList<User>();
		for (int i = 0; i < 900000; i++) {
			arrayList.add(user);
		}
		userService.addUsers(arrayList);
	}*/
	
	/*@Test
	public void batchUpdateByPrimaryKeySelective(){
		List<User> list = new ArrayList<User>();
		User user1 = new User();
		user1.setUserId(1000000000);
		user1.setUserName("xdp11");
		user1.setName("batchUpdateByPrimaryKeySelective");
		user1.setUpdater(0);
		list.add(user1);
		User user2 = new User();
		user2.setUserId(1000000001);
		user2.setUserName("xdp22");
		user2.setName("batchUpdateByPrimaryKeySelective");
		user2.setUpdater(0);
		list.add(user2);
		User user3 = new User();
		user3.setUserId(1000000002);
		user3.setUserName("xdp33");
		user3.setName("batchUpdateByPrimaryKeySelective");
		user3.setUpdater(0);
		list.add(user3);
		
		userService.batchUpdateByPrimaryKeySelective(list);
	}*/
	
	/*@Test
	public void batchUpdateByPrimaryKey(){
		List<User> list = new ArrayList<User>();
		User user1 = new User();
		user1.setUserId(1000000000);
		user1.setUserName("xdp11");
		user1.setName("batchUpdateByPrimaryKey1");
		user1.setUpdater(0);
		list.add(user1);
		User user2 = new User();
		user2.setUserId(1000000001);
		user2.setUserName("xdp22");
		user2.setName("batchUpdateByPrimaryKey1");
		user2.setUpdater(0);
		list.add(user2);
		User user3 = new User();
		user3.setUserId(1000000002);
		user3.setUserName("xdp33");
		user3.setName("batchUpdateByPrimaryKey1");
		user3.setUpdater(0);
		list.add(user3);
		
		userService.batchUpdateByPrimaryKey(list);
	}*/
	
	/*@Test
	public void queryListByPaging(){
		User user1 = new User();
		user1.setName("batchUpdateByPrimaryKey1");
		user1.setPage(300000);//网上说偏移量超过10000后，性能下降，但是这里只用了1.4秒，跟偏移量少的情况几乎无差
		user1.setPageSize(3);
		
		int total = userService.queryListByPaging(user1).get(0).getTotal();
		user1.setTotal(total);
		if(total>0){
			user1.setIsCount(false);
			user1.setRows(userService.queryListByPaging(user1));
		}
		System.out.println(user1.toString());
	}*/
	
	@Test
	public void selectArticleByUserId(){
		List<Article> list = articleService.selectArticleByUserId(1000000001);
		System.out.println(list.get(0).getUser().getEmail());
		System.out.println(list.get(0).getId());
	}
	
	

}
